<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax学习</title>
    <style>
        #result {
            height: 200px;
            width: 300px;
            border: 1px solid #000;

        }
    </style>
    <!-- <script src="server.js"></script> -->
</head>

<body>
    <button>请求服务</button>
    <div id="result"></div>
    <script>
        var bt = document.querySelector('button');
        var result = document.getElementById('result');
        bt.onclick = function () {
            const xhr = new XMLHttpRequest();
            xhr.open('GET', 'http://127.0.0.1:8888/server');
            xhr.send();
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200) {
                        console.log(xhr.status);
                        console.log(xhr.statusText);
                        console.log(xhr.getAllResponseHeaders);
                        console.log(xhr.response);
                        result.innerHTML = xhr.responseText;
                    } else {
                        console.log('cuole');
                    }
                }
            }
        }
    </script>
</body>

</html>